@extends('layouts.buz.layout')
@section('assets')
    <script src="{{asset('js/buz/template-web.js')}}"></script>

    <script id="list" type="text/html">
        @{{each data  value }}
        <div class="col-xs-12 col-sm-4 col-md-4 col-lg-3 ">
            <div class="commonIndex">
                <h4>
                    <cite class="circle">
                        @{{if value.classify==0}}
                        <img src="{{asset('image/brower-icon.png')}}"/>
                        @{{/if}}
                        @{{if value.classify==1}}
                        <img src="{{asset('image/androd-icon.png')}}"/>
                        @{{/if}}
                        @{{if value.classify==2}}
                        <img src="{{asset('image/apple-icon.png')}}"/>
                        @{{/if}}
                    </cite>
                    @{{value.name}}
                </h4>
                <div class="index-w">
                    <h3 class="fontsize2">@{{value.today_total_amt}}</h3>
                    <p>今日交易额（元）</p>
                    <h3 class="fontsize2">@{{value.today_total_order}}</h3>
                    <p>今日订单数</p>
                </div>
                <div class="row">
                    <div class="col-xs-4 col-xs-push-1">
                        <a href="/app/@{{value.id}}/orders">
                            <i class="iconfontM"></i>
                            <p>支付</p>
                        </a>
                    </div>
                    <div class="col-xs-4">
                        <a href="javascript:;">
                            <i class="iconfontF"></i>
                            <p>分析</p>
                        </a>
                    </div>
                    <div class="col-xs-4 col-xs-pull-1">
                        <a href="/app/@{{value.id}}">
                            <i class="iconfontS"></i>
                            <p>设置</p>
                        </a>
                    </div>
                </div>
            </div>
        </div>
        @{{/each}}
        <div class="col-xs-12 col-sm-4 col-md-4 col-lg-3 ">
            <div class="commonIndex commonW">
                <img src="{{asset('image/add.png')}}" width="50px" height="50px" id="openDialog">
            </div>
        </div>


    </script>
    <script>
        $.ajax({
            url: "/api/app",
            type: 'get',
            success:function(e){
                if(filterAjaxData(e)){
                    console.log(e);
                    var html = template('list', e);
                    document.getElementById('content').innerHTML = html;
                }
            }


        });
    </script>

@endsection()
@section('content')
    <div class="yhy-content col-sm-12">
<div class="col-sm-10">
    <div class="row" id="content">

    </div>
    </div >
    </div >
    @endsection()

@section('dialog')
<div class="modal fade" id="appAddFormDialog" tabindex="-1" role="dialog" >
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header y-modal-header-default">
                <button type="button" class="close" data-dismiss="modal">
                    <span aria-hidden="true">×</span>
                </button>
                <h3 class="modal-title">新建应用</h3>
            </div>
            <div class="modal-body">
                <form class="form-horizontal y-mt15 ng-pristine ng-valid fv-form fv-form-bootstrap" action="" method="post" id="submitForm" novalidate="novalidate"><button type="submit" class="fv-hidden-submit" style="display: none; width: 0px; height: 0px;"></button>
                    <div class="form-group">
                        <label for="userName" class="col-sm-3 control-label">应用平台</label>
                        <div class="col-xs-12 col-sm-8 text-xs-left">
                            <select class="form-control" name="classify" id="classify">
                                <option value="0">PC/WAP</option>
                                <option value="1">Android</option>
                                <option value="2">IOS</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group" >
                        <label for="websiteName" class="col-sm-3 control-label" id="websiteName">应用名称</label>
                        <div class="col-xs-12 col-sm-8 text-xs-left">
                            <input type="text" class="form-control" name="name" id="name" value=""  >
                        </div>
                    </div>
                    <div class="form-group" >
                        <label for="websiteDomain" class="col-sm-3 control-label" id="websiteDomain">网站域名</label>
                        <div class="col-sm-8 text-xs-left">
                            <input type="text" class="form-control" name="domain" id="domain" value="" >
                            <div class="y-notice">请如实填写，以防支付失败</div>
                        </div>
                    </div>
                    <div class="form-group" >
                        <label for="websiteIcp" class="col-sm-3 control-label" id="websiteIcp">ICP备案号</label>
                        <div class="col-sm-8 text-xs-left">
                            <input type="text" class="form-control" name="icp" id="icp" value="">
                            <div class="y-notice">请如实填写，以防支付失败</div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="websiteIcp" class="col-sm-3 control-label">消息通知url</label>
                        <div class="col-sm-8 text-xs-left">
                            <input type="text" class="form-control" name="notify_url" id="notify_url" value="">
                            <div class="y-notice">请如实填写，以防支付失败</div>
                        </div>
                    </div>



                </form>
            </div>
            <div class="modal-footer y-modal-footer-default">
                <input type="button" class="btn btn-info center-block y-app-add-create" id="saveAppBtn" value="创建" onclick="createAppSubmit();">
            </div>
        </div>
    </div>
</div>
@endsection()

@section('bottom_js')

<script>

    $(function(){
        $("#content").on("click","#openDialog",function () {
            console.log("ddd")
            $("#appAddFormDialog").modal("toggle");
        })

        $("select[name='classify']").change(function(){
            var sel_val = $(this).val();
            if(sel_val == 0){
                $("#websiteIcp").parent(".form-group").show();
                $("#websiteDomain").text("应用域名");
                $("#websiteIcp").text("icp备案号");
            }else if(sel_val == 1){
                $("#websiteIcp").parent(".form-group").show();
                $("#websiteDomain").text("安卓签名");
                $("#websiteIcp").text("安卓包名");
            }else if(sel_val == 2){
                $("#websiteDomain").text("iosbundleid");
                $("#websiteIcp").parent(".form-group").hide();
            }else {
                alert("操作错误");
            }
        });



    });

    $('#submitForm').bootstrapValidator({
        message: '这个值没有被验证',
        feedbackIcons: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
        fields: {
            name: {
                message: '不能为空',
                validators: {
                    notEmpty: {
                        message: '不能为空'
                    }

                }
            },
            domain: {
                message: '不能为空',
                validators: {
                    notEmpty: {
                        message: '不能为空'
                    }
                }
            },
            icp: {
                message: '不能为空',
                validators: {
                    notEmpty: {
                        message: '不能为空'
                    }
                }
            },
            notify_url: {
                message: '消息通知url不能为空',
                validators: {
                    notEmpty: {
                        message: '消息通知url不能为空'
                    }
                }
            }
        }
    });
    function  createAppSubmit() {
        var bootstrapValidator = $('#submitForm').data("bootstrapValidator");
        bootstrapValidator.validate();
        if(bootstrapValidator.isValid()){
            var data = $("#submitForm").serialize();
            console.log(data);
            $.ajax({
                url: "/api/app",
                data: data,
                type: 'post',
                success:function(data){
                    console.log(data);
                    if(filterAjaxData(data)){
                       location=location;
                    }else {
                        var str=""
                        if(data.message.name){str+=data.message.name};
                        if(data.message.domain){str+=data.message.domain};
                        if(data.message.icp){str+=data.message.icp};
                        showMsg(str);
                    }

                }

            });
        }

    }
</script>
@endsection()
